package com.cqjtu.tto.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class DateHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("taskStartTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("projectStartTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("creatTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("uploadTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("stageStartTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("projectDeleted",0,metaObject);
        this.setFieldValByName("taskDeleted",0,metaObject);
        this.setFieldValByName("projectStageDeleted",0,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("projectCompleteTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("stageEndTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("taskEndTime",LocalDateTime.now(),metaObject);
    }
}
